/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.femass.repository.infra;

import com.femass.model.Aluno;
import com.femass.repository.AlunoRepository;
import com.femass.util.FacesUtil;
import java.util.List;
import javax.faces.application.FacesMessage;
import org.hibernate.Session;

/**
 *
 * @author daureo
 */
public class AlunoRepositoryHibernate implements AlunoRepository{

    @Override
    public List<Aluno> todos() {
        Session session = (Session) FacesUtil.getRequestAttribute("session");
        return session.createCriteria(Aluno.class)
                .list();
    }

    @Override
    public void salvar(Aluno aluno) {
        Session session = (Session) FacesUtil.getRequestAttribute("session");
       try{
            session.persist(aluno);                       
            FacesUtil.adicionarMensagem(FacesMessage.SEVERITY_INFO, "Aluno Salvo!");
       } catch(Exception e){
            FacesUtil.adicionarMensagem(FacesMessage.SEVERITY_WARN, "Erro ao salvar Aluno!" + e.getMessage());
       }
    }
    
}
